package com.barcamp.dao;

import java.util.List;

//import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.barcamp.entity.EventType;
import com.exception.PersistenceException;


public class EventTypeDao extends SqlMapClientDaoSupport{
	//private Logger logger = Logger.getLogger(EventTypeDao.class);
	public void insertNew(EventType evType)throws PersistenceException
	{
		try{
			getSqlMapClientTemplate().insert("EventType.insert", evType);
			//logger.info( evType.getName() + " is successfully inserted.");
		}catch(DataAccessException ex){
			// logger.error(evType.getName() + " is failed to insert.", ex);
	         throw new PersistenceException("Failed to insert.", ex);
		}
	}
	  public void update(EventType evType) throws PersistenceException 
	  {
	      try {
	          getSqlMapClientTemplate().update("EventType.update", evType);
	         // logger.info("EventType (" + evType.getName() +  ") is successfully updated.");
	      } catch (DataAccessException ex) {
	          //logger.error("EventType (" + evType.getName() +  ") is failed to update.");
	          throw ex;
	      }
	  }
	  public EventType delete(int id) throws PersistenceException 
	  {
	      EventType result=null;
	      try {
	          getSqlMapClientTemplate().delete("EventType.delete", id);
	          //logger.info("EventType ( id =" + id +  ") is successfully found.");
	      } catch (DataAccessException ex) {
	          //logger.error("EventType ( id =" + id +  ") is failed to find.");
	          throw ex;
	      }
	     return result;
	  }
	  public List<EventType> findAll() throws PersistenceException 
	  {
	      List<EventType> result = null;
	      try {
	          result =(List<EventType>)getSqlMapClientTemplate().queryForList("EventType.findAllEvent");
             // logger.info("All of books is successfully found.");
	      } catch (DataAccessException ex) {
	          //logger.error("All of books is failed to find.");
	          throw ex;
	      }
	      return result;
	  }
	  public EventType findByID(int id) throws PersistenceException 
	  {
	      EventType result;
	      try {
	          result = (EventType)getSqlMapClientTemplate().queryForObject("EventType.findByID", id);
	        //  logger.info("All of User is successfully found.");
	      } catch (DataAccessException ex) {
	         // logger.error("All of User is failed to find.");
	          throw ex;
	      }
	      return result;
	  }
	 
	}
